package backend;
import java.util.Vector;

/**
* This class represents a user in general hierachical RBAC (2a). A user has a 
* name and a set of roles.
* 
* @author Aaron A. Lovato
*/

public class User
{
    // This user's username
    private String name;
    
    // This user's password
    private String password;
    
    // Role's this user is assigned
    private Vector<Role> roles;
    
    /**
     * Creates a User object.
     * @param name Username to assign to the new user.
     * @param password Password to give this user.
     */
    public User(String name, String password)
    {
        roles = new Vector<Role>();
        this.name = name;
        this.password = password;
    }
    
    /**
     * Returns this user's username.
     * @return This user's username.
     */
    public String getName()
    {
        return name;
    }
    
    /**
     * Sets this user's username.
     * @param name Username to assign to this user.
     */
    public void setName(String name)
    {
        this.name = name;
    }
    
    /**
     * Get this user's password.
     * @return This user's password.
     */
    public String getPassword()
    {
        return this.password;
    }
    
    /**
     * Set this user's password.
     * @param password Password to assign this user.
     */
    public void setPassword(String password)
    {
        this.password = password;
    }
    
    /** 
     * Adds a role to this user.
     * @param role Role to assign.
     */
    public void addRole(Role r)
    {
        this.roles.add(r);
    }
    
    /**
     * Remove a role from this user.
     * @param role Role to remove.
     */
    public void removeRole(Role r)
    {
        this.roles.remove(r);
    }
    
    /**
     * Get all of the roles this user is assigned.
     * @return A Vector containing all roles this user is assigned.
     */
    public Vector<Role> getRoles()
    {
        return new Vector<Role>(roles);
    }

    /**
     * Print out a User in a pretty string for testing.
     * @return A string representing a User.
     */
    public String toString()
    {
        return "(" + this.name + ", " + this.password + ")";
    }
}
